// app.js
App({
  globalData: {
    appid: 'wx1e561ab233eb973a',
    baseUrl: 'http://127.0.0.1:8088',
    userInfo: null
  },

  onLaunch() {
    // Check login status
    const token = wx.getStorageSync('token');
    if (token) {
      this.checkLoginStatus(token);
    }
  },

  checkLoginStatus(token) {
    wx.request({
      url: `${this.globalData.baseUrl}/auth/userInfo`,
      header: {
        'Authorization': token
      },
      success: (res) => {
        if (res.data.code === 200) {
          this.globalData.userInfo = res.data.data;
        } else {
          wx.removeStorageSync('token');
        }
      },
      fail: () => {
        wx.removeStorageSync('token');
      }
    });
  }
});
